/*
 * @lc app=leetcode.cn id=48 lang=cpp
 *
 * [48] 旋转图像
 */
#include "include.h"
// @lc code=start
class Solution {
public:
int n, half, half_;
    void rotate(vector<vector<int>>& matrix) {
        n = matrix.size();
        half = n/2;
        half_ = half + n%2;

        for (int i=0;i<half;++i){
            for (int j=0;j<half_;++j){
                rotate4cells(matrix, i, j);
            }
        }
    }
    void rotate4cells(vector<vector<int>>& matrix, int i, int j){
        
        int temp = matrix[i][j];
        matrix[i][j] = matrix[n-1-j][i];
        matrix[n-1-j][i] = matrix[n-1-i][n-1-j];
        matrix[n-1-i][n-1-j] = matrix[j][n-1-i];
        matrix[j][n-1-i] = temp;
    }
};
// @lc code=end

